#!/bin/sh

if ! head -1 "$1" | grep -qE "^(feat|fix|ci|chore|docs|test|style|refactor|perf|build|revert)(\(.+?\))?: .{1,}\[.+\]$"; then
    echo "" >&2
    echo "Aborting commit. Your commit message must adhere to the following format." >&2
    echo "  <type>: <subject> [issue tag]" >&2
    echo "" >&2
    echo "Where:" >&2
    echo "  <type>      - Type of the change (e.g., feat, fix, ci, chore, docs, test, style, refactor, perf, build, revert)." >&2
    echo "  <subject>   - Brief description of the change." >&2
    echo "  [issue tag] - Issue tag enclosed in square brackets." >&2
    echo "" >&2
    echo "Example:" >&2
    echo "  feat: add authentication to the login endpoint [SPRW-1234]" >&2
    exit 1
fi
if ! head -1 "$1" | grep -qE "^.{1,200}$"; then
    echo "Aborting commit. Your commit message must be under 200 characters." >&2
    exit 1
fi